//
//  LMBadgeView.m
//  李明微博
//
//  Created by apple on 15/12/4.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMBadgeView.h"

#define LMBadgViewFlont [UIFont systemFontOfSize:11]

@implementation LMBadgeView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self= [super initWithFrame:frame]) {
        
        
        //用户点击按钮被忽略
        self.userInteractionEnabled = NO;
        
        [self setBackgroundImage:[UIImage imageNamed:@"main_badge"] forState:UIControlStateNormal];
        
        self.titleLabel.font = LMBadgViewFlont;
        
        [self sizeToFit];
    }
    return self;
}


- (void)setBadageValue:(NSString *)badageValue

{
    _badageValue = badageValue;
    
    if (badageValue.length == 0 || [badageValue isEqualToString:@"0"]) {
        
        self.hidden = YES;
    }
    else
    {
        self.hidden = NO;
    }
    
    
    
    
    CGSize fontsize = [badageValue sizeWithAttributes:@{NSFontAttributeName:LMBadgViewFlont}];
    
    if (fontsize.width > self.width) {
        [self setImage:[UIImage imageNamed:@"new_hot"] forState:UIControlStateNormal];
        [self setTitle:nil forState:UIControlStateNormal];
        [self setBackgroundImage:nil forState:UIControlStateNormal];
    }
    else
    {
        [self setBackgroundImage:[UIImage imageNamed:@"main_badge"] forState:UIControlStateNormal];
        [self setTitle:badageValue forState:UIControlStateNormal];
        [self setImage:nil forState:UIControlStateNormal];
    }
    
    
    
    
}




@end
